/**
 * 说明：
 * 创建人：pluto
 * 创建时间：2018/8/3
 */
var ProtocolCtrl = function ($scope, $stateParams, ProtocolService) {
    console.log($stateParams.type);
    $scope.protocol = {};
    $scope.config = {
        //初始化编辑器内容
        content: '<p></p>',
        //是否聚焦 focus默认为false
        focus: true,
        //首行缩进距离,默认是2em
        indentValue: '2em',
        //初始化编辑器宽度,默认1000
        initialFrameWidth: 900,
        //初始化编辑器高度,默认320
        initialFrameHeight: 350,
        //编辑器初始化结束后,编辑区域是否是只读的，默认是false
        readonly: false,
        //启用自动保存
        enableAutoSave: false,
        //自动保存间隔时间， 单位ms
        saveInterval: 500,
        //是否开启初始化时即全屏，默认关闭
        fullscreen: false,
        //图片操作的浮层开关，默认打开
        imagePopup: true,
        //提交到后台的数据是否包含整个html字符串
        allHtmlEnabled: false,
        functions: []
    };
    $scope.getContent = function (id) {
        $scope.protocol.content = $scope.ueditorGetContent(id);

        if ($scope.protocol.id) {
            $scope.protocol.type = $stateParams.type;
            ProtocolService.update($scope.protocol).then(function () {
                layer.msg("保存成功", {icon: 1})
            }, function (err) {
                layer.msg(err.message, {icon: 2})
            })
        } else {
            ProtocolService.save({content: $scope.protocol.content, type: $stateParams.type}).then(function () {
                layer.msg("保存成功", {icon: 1})
            }, function (err) {
                layer.msg(err.message, {icon: 2})
            })
        }

    };
    $scope.getContentTxt = function (id) {
        var content = $scope.ueditorGetContentTxt(id);
        alert(content);
    };

    $scope.setContent=function(){
        $scope.ueditorSetContent("container","111111");
    }

    $scope.$on('$viewContentLoaded', function() {
        ProtocolService.getByType($stateParams.type).then(function (res) {
            if (res) {
                $scope.protocol = res;
                $scope.ueditorSetContent("container", res.content);
            }
        })
    });

};

angular.module('app.system.protocol.controller', []).controller("ProtocolCtrl", ProtocolCtrl);

